local lsp_lingyun = fk.CreateSkill {
    name = "lsp_lingyun",
    anim_type = "drawcard",
    tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
    ["lsp_lingyun"] = "棂韵",
    [":lsp_lingyun"] = "锁定技，游戏开始时，你摸体力值等量的牌，将其标记为“韵”，这些牌进入弃牌堆后，你将其置于你的武将牌上，然后摸X张牌(X为你武将牌上的牌总和，至多为你的体力上限)。",

    ["@@lsp_lingyun"] = "韵",
}

lsp_lingyun:addEffect(fk.GameStart, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(lsp_lingyun.name)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = player:drawCards(player.hp, lsp_lingyun.name)
        for _, id in ipairs(cards) do
            room:setCardMark(Fk:getCardById(id), "@@lsp_lingyun", 1)
        end
    end,
})

lsp_lingyun:addEffect(fk.AfterCardsMove, {
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(lsp_lingyun.name) then
            local cards = {}
            for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile then
                    for _, info in ipairs(move.moveInfo) do
                        if Fk:getCardById(info.cardId):getMark("@@lsp_lingyun") > 0 then
                            table.insertIfNeed(cards, info.cardId)
                        end
                    end
                end
            end
            cards = player.room.logic:moveCardsHoldingAreaCheck(cards)
            if #cards > 0 then
                event:setCostData(self, { cards = cards })
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = table.filter(event:getCostData(self).cards, function(c)
            return table.contains(room.discard_pile, c)
        end)
        if #cards == 1 then
            player:addToPile(lsp_lingyun.name, cards, true, lsp_lingyun.name, player)
            local num = {}
            for _, t in pairs(player.special_cards) do
                table.insertTableIfNeed(num, t)
            end
            player:drawCards(math.min(#num, player.maxHp), lsp_lingyun.name)
        else
            local n = #cards
            for i = 1, n, 1 do
                local card = room:askToChooseCard(player, { --从特定卡牌组中选择一张示范
                    target = player,
                    flag = { card_data = { { lsp_lingyun.name, cards } } },
                    skill_name = lsp_lingyun.name,
                    prompt = "请选择要要置于武将牌上的牌",
                })
                table.removeOne(cards, card)
                player:addToPile(lsp_lingyun.name, card, false, lsp_lingyun.name, player)
                local num = {}
                for _, t in pairs(player.special_cards) do
                    table.insertTableIfNeed(num, t)
                end
                player:drawCards(math.min(#num, player.maxHp), lsp_lingyun.name)
            end
        end
    end,
})
return lsp_lingyun
